import { defineStore } from "pinia";

export interface UseLogin {
  access_token: string,
  client_id: string,
  expire_in: string,
  openid: string,
  refresh_token: string,
  refresh_expire_in: string,
  scope:string,
  user:string,
}

const useLogin = defineStore("useLogin", {
  state: (): UseLogin => {
    return {
      access_token: '',
      client_id: '',
      expire_in: '',
      openid: '',
      refresh_token: '',
      refresh_expire_in: '',
      scope:'',
      user:'',
    }
  },
  actions: {
    setState(data) {
      this.access_token=data.access_token
      this.client_id=data.client_id
      this.expire_in=data.expire_in
      this.openid=data.openid
      this.refresh_token=data.refresh_token
      this.refresh_expire_in=data.refresh_expire_in
      this.scope=data.scope
    },
    // 在 useLogin 的 actions 中添加
    resetState() {
      this.access_token = '';
      this.client_id = '';
      this.expire_in = '';
      this.openid = '';
      this.refresh_token = '';
      this.refresh_expire_in = '';
      this.scope = '';
      this.user = '';
    }

  },
});

export default useLogin;